﻿namespace WMS6.Web.Outbound
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.OutboundDetailServiceRef;
    using WMS6.Web.OutboundServiceRef;

    public class BatchOrderDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected Button btnSaveContinue;
        protected HtmlForm F7033;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnOrderBatchFlag;
        protected HtmlInputHidden hdnWaveID;
        protected HtmlHead Head1;
        protected HtmlImage imgOrderID;
        protected Label lblBatchOrderDetail;
        protected Label lblConsigneeID;
        protected Label lblDoor;
        protected Label lblMsg;
        protected Label lblOrderDate;
        protected Label lblOrderID;
        protected Label lblOwnerID;
        protected Label lblPriority;
        protected Label lblRequestedShipDate;
        protected Label lblRoute;
        protected Label lblStatus;
        protected Label lblStop;
        protected Label lblType;
        protected Label lblWaveID;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtConsigneeID;
        protected TextBox txtDoor;
        protected TextBox txtOrderDate;
        protected TextBox txtOrderID;
        protected TextBox txtOwnerID;
        protected TextBox txtPriority;
        protected TextBox txtRequestedShipDate;
        protected TextBox txtRoute;
        protected TextBox txtStatus;
        protected TextBox txtStop;
        protected TextBox txtType;
        protected TextBox txtWaveID;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("BatchOrder.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnWaveID.Value.Trim())));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool success = false;
                if (!string.IsNullOrEmpty(this.txtOrderID.Text))
                {
                    WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo waveDetail = new WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo {
                        WaveID = this.txtWaveID.Text,
                        OrderID = this.txtOrderID.Text,
                        ProcessStatus = this.txtStatus.Text,
                        CreatedBy = base.UserInfo.UserID
                    };
                    if (!string.IsNullOrEmpty(OutboundDetailServiceClientProxy.GetInstance().InsertWaveDetail(waveDetail)))
                    {
                        success = true;
                    }
                }
                else
                {
                    this.txtOrderID.Focus();
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7300_016");
                    this.lblMsg.Visible = true;
                }
                if (success)
                {
                    base.Response.Redirect(string.Format("BatchOrder.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnWaveID.Value.Trim())));
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            try
            {
                bool success = false;
                if (!string.IsNullOrEmpty(this.txtOrderID.Text))
                {
                    WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo waveDetail = new WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo {
                        WaveID = this.txtWaveID.Text,
                        OrderID = this.txtOrderID.Text,
                        ProcessStatus = this.txtStatus.Text,
                        CreatedBy = base.UserInfo.UserID
                    };
                    if (!string.IsNullOrEmpty(OutboundDetailServiceClientProxy.GetInstance().InsertWaveDetail(waveDetail)))
                    {
                        success = true;
                    }
                }
                else
                {
                    this.txtOrderID.Focus();
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7300_016");
                    this.lblMsg.Visible = true;
                }
                if (success)
                {
                    this.txtConsigneeID.Text = "";
                    this.txtDoor.Text = "";
                    this.txtOrderDate.Text = "";
                    this.txtOrderID.Text = "";
                    this.txtOwnerID.Text = "";
                    this.txtPriority.Text = "";
                    this.txtRequestedShipDate.Text = "";
                    this.txtRoute.Text = "";
                    this.txtStatus.Text = "";
                    this.txtStop.Text = "";
                    this.txtType.Text = "";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.hdnFrom.Value = base.Request.QueryString["from"];
                this.hdnWaveID.Value = base.Request.QueryString["ID"];
                this.txtWaveID.Text = this.hdnWaveID.Value;
            }
            this.lblMsg.Text = "";
        }

        protected void txtOrderID_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtOrderID.Text))
                {
                    OrdersInfo orderInfo = OutboundServiceClientProxy.GetInstance().GetOrdersInfoByOrderID(this.txtOrderID.Text);
                    if ((orderInfo != null) && !string.IsNullOrEmpty(orderInfo.OrderID))
                    {
                        this.txtOwnerID.Text = orderInfo.OwnerID;
                        this.txtOrderDate.Text = base.GetPreferenceShortDate(orderInfo.OrderDate);
                        this.txtStatus.Text = orderInfo.Status;
                        this.txtConsigneeID.Text = orderInfo.ConsigneeID;
                        this.txtType.Text = orderInfo.Type;
                        this.txtPriority.Text = orderInfo.Priority;
                        this.txtRequestedShipDate.Text = base.GetPreferenceShortDate(orderInfo.RequestedShipDate);
                        this.txtDoor.Text = orderInfo.Door;
                        this.txtRoute.Text = orderInfo.Route;
                        this.txtStop.Text = orderInfo.Stop;
                        this.hdnOrderBatchFlag.Value = orderInfo.BatchFlag;
                        if (orderInfo.Status.ToUpper() != "NEW")
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F7300_017");
                            this.lblMsg.Visible = true;
                            this.txtOrderID.Text = "";
                        }
                        else if (orderInfo.BatchFlag == "Y")
                        {
                            this.btnSave.Enabled = false;
                            this.btnSaveContinue.Enabled = false;
                            this.lblMsg.Text = base.GetGlobalMsgResource("F7300_018");
                            this.txtOrderID.Text = "";
                            this.lblMsg.Visible = true;
                        }
                        else
                        {
                            this.btnSave.Enabled = true;
                            this.btnSaveContinue.Enabled = true;
                            this.lblMsg.Text = "";
                            this.lblMsg.Visible = false;
                        }
                    }
                    else
                    {
                        this.txtOrderID.Text = "";
                        this.lblMsg.Text = base.GetGlobalMsgResource("F7300_019");
                        this.lblMsg.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }
    }
}

